package exam.test17;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-12-17
 * Time: 9:12
 */
public class PlayUtil {

    /**
     * generate object for rock, paper and scissors
     * @param input
     * @return
     */
    public static Object genObject(String input) {

        if (input != null) {
            if (input.equalsIgnoreCase("Rock")) {
                return new Rock();
            } else if (input.equalsIgnoreCase("Paper")) {
                return new Paper();
            } else if (input.equalsIgnoreCase("Scissors")) {
                return new Scissors();
            }
        }
        return null;
    }

    /**
     * @param object1
     * @param object2
     * @return 0 draw,  1 from object1 win, 2 from object2 win
     */
    public static int check(Object object1, Object object2) {
        if (object1.getClass().equals(object2.getClass())) {
            return 0;
        } else if (object1 instanceof Rock && object2 instanceof Paper) {
            return 2;
        } else if (object1 instanceof Paper && object2 instanceof Scissors) {
            return 2;
        } else if (object1 instanceof Scissors && object2 instanceof Rock) {
            return 2;
        }
        return 1;
    }
}

class Rock{

}

class Paper {

}

class Scissors {

}